package cn.wangxl.loglog.listener;

import cn.wangxl.loglog.constants.Application;
import cn.wangxl.loglog.constants.LogTypeEnum;
import cn.wangxl.loglog.domain.ServiceBuryingPointLogDO;
import cn.wangxl.loglog.service.LogService;
import cn.wangxl.loglog.service.bo.BasicLogBO;
import cn.wangxl.loglog.util.DozerUtils;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Description 消费数据
 * @Classname RockmqListener
 * @Created by wangxl
 * @Date 2020/5/10 23:59
 */
@Component
@RocketMQMessageListener(
        topic = "service",
        consumerGroup = "serviceGroup",
        messageModel = MessageModel.CLUSTERING
)
public class RockmqServiceListener implements RocketMQListener<BasicLogBO> {

    @Autowired
    private LogService logService;

    @Override
    public void onMessage(BasicLogBO basicLogBO) {
        System.out.println("消费数据");
        ServiceBuryingPointLogDO serviceBuryingPointLogDO = DozerUtils.convert(basicLogBO, ServiceBuryingPointLogDO.class);
        logService.saveLog(serviceBuryingPointLogDO,
                Application.getByName(basicLogBO.getApplication()),
                LogTypeEnum.getByType(basicLogBO.getLogType()).getType());
    }
}
